import 'package:flutter/material.dart';
import 'package:meal/components/group/order.dart';
import 'package:meal/constant/sizes.dart';
import 'package:meal/utils/styles.dart';
import 'package:meal/utils/tools.dart';

///
/// 团购订单列表
///
class GroupOrderList extends StatefulWidget {
  const GroupOrderList({Key? key}) : super(key: key);

  @override
  State<GroupOrderList> createState() => _GroupOrderListState();
}

class _GroupOrderListState extends State<GroupOrderList> with SingleTickerProviderStateMixin {
  late TabController _controller;

  List<String> tabs = ['全部', '未使用', '已退款'];

  Widget get title {
    return Text('团购订单', style: StylesUtils.customTextStyle(fontSize: Sizes.default18));
  }

  PreferredSizeWidget get bottom {
    return PreferredSize(
      preferredSize: const Size.fromHeight(Sizes.default50),
      child: Container(
        alignment: Alignment.center,
        decoration: const BoxDecoration(color: Colors.white),
        child: ToolsUtils.getClientTabBar(tabs, _controller),
      ),
    );
  }

  @override
  void initState() {
    super.initState();
    _controller = TabController(length: tabs.length, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ToolsUtils.getDefaultBackgroundColor(),
      appBar: ToolsUtils.customBrnAppBar(title, bottom: bottom),
      body: TabBarView(
          controller: _controller,
          children: tabs.asMap().map((key, value) => MapEntry(key, const GroupOrder())).values.toList()),
    );
  }
}
